﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace Golf.WebUI.AdminShow.CommoditiesMmanagement
{
    public partial class Golf_BrandTypeAdd : Golf.WebUI.App_code.ValidateLogin
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int Id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(Id);
                }
            }
        }

        private void ShowInfo(int Id)
        {
            Golf.BLL.Golf_BrandType bll = new Golf.BLL.Golf_BrandType();
            Golf.Model.Golf_BrandType model = bll.GetModel(Id);
            this.lblId.Text = model.Id.ToString();
            this.txtTypeName.Text = model.TypeName;
            this.txtAddAdminId.Text = model.AddAdminId.ToString();
            this.txtAddTime.Text = model.AddTime.ToString();
            this.chkIsCommend.Checked = model.IsCommend;
            this.chkIsDisplay.Checked = model.IsDisplay;

        }
        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtTypeName.Text.Trim().Length == 0)
            {
                strErr += "品牌分类名称不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtAddAdminId.Text))
            {
                strErr += "添加管理人id	Golf_Ad格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtAddTime.Text))
            {
                strErr += "添加品牌分类时间格式错误！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string TypeName = this.txtTypeName.Text;
            int AddAdminId = int.Parse(this.txtAddAdminId.Text);
            DateTime AddTime = DateTime.Parse(this.txtAddTime.Text);
            bool IsCommend = this.chkIsCommend.Checked;
            bool IsDisplay = this.chkIsDisplay.Checked;

            Golf.Model.Golf_BrandType model = new Golf.Model.Golf_BrandType();
            model.TypeName = TypeName;
            model.AddAdminId = AddAdminId;
            model.AddTime = AddTime;
            model.IsCommend = IsCommend;
            model.IsDisplay = IsDisplay;

            Golf.BLL.Golf_BrandType bll = new Golf.BLL.Golf_BrandType();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "add.aspx");

        }

    }
}
